﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace MyMovieSystem
{
    /// <summary>
    /// 管理票类
    /// </summary>
    class TicketManage
    {
        /// <summary>
        /// 存储售出的票
        /// </summary>
        public static List<Ticket> listTick = new List<Ticket>();

         /// <summary>
        /// 初始化已购买的票
        /// </summary>
        public static void InitialTicket()
        {
            //创建文件流
            FileStream fs = new FileStream("data//TicketInfo.bin", FileMode.Open);
            //创建序列化文本类
            BinaryFormatter bf = new BinaryFormatter();
            listTick = (List<Ticket>)bf.Deserialize(fs);
            fs.Close();
        }

        #region 序列化数据

        /// <summary>
        /// 序列化影厅
        /// </summary>
        public  static void SerializeTicket()
        {
            //创建文件流
            FileStream fs = new FileStream("data//TicketInfo.bin", FileMode.Create);
            //创建序列化文本类
            BinaryFormatter bf = new BinaryFormatter();
            //序列化
            bf.Serialize(fs, listTick);
            fs.Close();
        }
        #endregion
    }
}
